package ch.zbw.pra.sysventory.presentation.panels;

import java.util.List;

import ch.zbw.pra.sysventory.application.controller.OperatingSystemController;
import ch.zbw.pra.sysventory.model.OperatingSystem;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

/**
 * Painted das OperatingSystemsArchivePanel
 * 
 * @author Ralph Koster
 */

public class OperatingSystemsArchivePanel extends VerticalLayout {

	private static final long serialVersionUID = 1L;
	private OperatingSystemController operatingSystemController;
	private Table operatingSystemsTable;

	public OperatingSystemsArchivePanel() {
		this.operatingSystemsTable = new Table("Betriebssysteme im Netzwerk:");
		this.operatingSystemController = new OperatingSystemController();
		paint();
		loadOperatingSystems();
	}

	private void paint() {
		this.setCaption("Betriebssysteme");
		this.setStyleName("operatingSystemArchivePanel");
		operatingSystemsTable.setStyleName("table");
		operatingSystemsTable.addContainerProperty("Betriebssystem Name",String.class, null);
		operatingSystemsTable.addContainerProperty("Version", String.class,null);
		operatingSystemsTable.addContainerProperty("Bit", String.class, null);
		this.addComponent(operatingSystemsTable);
		this.setComponentAlignment(operatingSystemsTable, Alignment.MIDDLE_CENTER);
	}

	private void loadOperatingSystems() {
		operatingSystemsTable.removeAllItems();
		List<OperatingSystem> operatingSystems = operatingSystemController.loadOperatingSystems();
		for (OperatingSystem operatingSystem : operatingSystems) {
			int operatingSystemId = operatingSystem.getOperatingSystemId();
			String operatingName = operatingSystem.getNameOperatingSystem();
			String operatingVersion = operatingSystem.getBuildOperatingSystem();
			String operatingBit = operatingSystem.getArchitecture32Bit64BitOperatingSystem();
			operatingSystemsTable.addItem(new Object[] { 
					operatingName,operatingVersion, operatingBit }, operatingSystemId);
		}

	}

	public void updateOperatingSystemArchivePanel() {
		loadOperatingSystems();
	}

}
